package com.powernobug.service.impl;

import com.github.pagehelper.PageHelper;
import com.powernobug.bean.model.MarketBrand;
import com.powernobug.bean.model.MarketBrandExample;
import com.powernobug.bean.vo.template.BrandsTempForHomeIndex;
import com.powernobug.mapper.MarketBrandMapper;
import com.powernobug.annotation.PrintThreadLog;
import com.powernobug.service.MarketBrandService;
import com.powernobug.util.TransferModelDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;

/**
 * @Author: 肖云戈
 * @CreateTime: 2024-08-30
 * @Description:
 */
@Service
public class MarketBrandServiceImpl implements MarketBrandService {

    @Autowired
    MarketBrandMapper marketBrandMapper;

    @Override
    @Async("globalThreadPool")
    @PrintThreadLog
    public Future<List<BrandsTempForHomeIndex>> getBrandListByLimit(int brandListLimit) {
        MarketBrandExample example = new MarketBrandExample();
        example.createCriteria().andDeletedEqualTo(false);
        example.setOrderByClause("add_time desc");
        PageHelper.startPage(1, brandListLimit);

        List<MarketBrand> originData = marketBrandMapper.selectByExample(example);
        Class<?> resultType = BrandsTempForHomeIndex.class;
        List<BrandsTempForHomeIndex> resultData = (List<BrandsTempForHomeIndex>) TransferModelDataUtil.transferFatherToSon(resultType, originData);
        return new AsyncResult<>(resultData);
    }
}
